<?php
/*************************************************************************************
 *
 *	FileName: /edp/module/find_user_pwd/header_php.php
 *	Desc    : find_user_pwd page
 *	Author  : andrew
 *	Date    : 2009-12-22
 *
 *************************************************************************************/

$errmsg = GetMessageStack();
if(isset($_POST['email']))
	$email=trim($_POST['email']);
else 
	$email='';
		
if(isset($_POST['vcode']))
	$vcode=trim($_POST['vcode']);
else 
	$vcode='';
	
if(isset($_POST['redir']))
	$redirect=trim($_GET['redir']);
else 
	$redirect='';
	
function FindPwd()
{
	global $errmsg, $email, $vcode;
	
	/*
	 * 服务器端验证
	 */
	if( $vcode != edp_getsession( 'vcode' ) )
	{
		$errmsg->add( 'find_pwd', '验证码无效！' );
		return;
	}
	if( edp_is_empty_string($email) || !preg_match('/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$/', $email) 
		||strlen($email)>'30')
	{
		$errmsg->add( 'find_pwd', '输入的Email格式错误,请重新输入！' );
		return;
	}
	
	$userDAO=GetUserDAO();
	if(($user=$userDAO->IsEmailExist($email))==false)
	{
		$errmsg->add( 'find_pwd', '此Email没有被注册,请重新输入！ ' );
		return;
	}
	
	$pwd=$userDAO->SetNewPwd($email);
	
	//Send Mail
	$mail=GetMailer();
	$mail->SendFindPwdMail($email, $user['nick'], $pwd);
	
	TransferTo('find_pwd_success');
	return;
}

if(isset($_POST['action']))
{
	$action=trim($_POST['action']);
	if($action=='find_pwd') 
	{
		FindPwd();
	}
}

?>
